package com.lineage.data.item_etcitem.shop;

import com.lineage.config.ConfigOther;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UserTitle extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(UserTitle.class);
  
  public static ItemExecutor get() {
    return new UserTitle();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    if (pc.isGhost())
      return; 
    if (pc.isDead())
      return; 
    if (pc.isTeleport())
      return; 
    if (pc.is_repass() != 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fU你不是要变更密码吗?"));
      return;
    } 
    if (!ConfigOther.CLANTITLE) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT尚未开放"));
      return;
    } 
    if (pc.isPrivateShop()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先结束商店村模式!"));
      return;
    } 
    try {
      pc.retitle(true);
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fR输入封号后直接按下ENTER"));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
